import {
    Score
} from './score.model'
import {
    Config
} from '../../utils/config'
import Toast from '@vant/weapp/toast/toast'
const score = new Score()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        licensenumber: '123456789123456789',
        licenseid: '123456798123',
        score: '5',
        scoreModel: false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 提交查询
     * @param {*} options
     */
    doSubmit(options) {
        let that = this,
            errMsg = '',
            value = options.detail.value
        if (value.licenseid && !/^\d{12}$/.test(value.licenseid)) {
            errMsg = '档案编号格式不正确'
        }
        if (!value.licenseid) {
            errMsg = '档案编号不能为空'
        }
        if (value.licensenumber && !Config.idCard.test(value.licensenumber)) {
            errMsg = '驾驶证号格式不正确'
        }
        if (!value.licensenumber) {
            errMsg = '驾驶证号不能为空'
        }
        if (errMsg) {
            Toast(errMsg)
            return false
        }
        score.getScoreData(value).then((res) => {
            that.setData({
                scoreModel: true,
                score: res.data.score
            })
        })
    },

    /**
     * 点击确定
     */
    onConfirm() {
        wx.navigateBack({
            delta: 1,
        })
    }
})